﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AForge;
using AForge.Genetic;

namespace dto
{
   public class doubleNullValue:IFitnessFunction 
    {
        //-------------------- for DoubleArrayChromosome
        double IFitnessFunction.Evaluate(IChromosome chromosome)
        {
            myDoubleArrayChromosome chromosome1 = (myDoubleArrayChromosome)chromosome;
            double sumXj = -(chromosome1.Length + 1), prodXj = 1, xi, sumFunctions = 0;

            for (int i = 0; i < chromosome1.Length; i++)
            {
                xi = chromosome1.Value[i];
                sumXj += xi;
                prodXj *= xi;
            }

            for (int i = 0; i < chromosome1.Length - 1; i++)
            {
                xi = chromosome1.Value[i];
                sumFunctions += Math.Pow(xi + sumXj, 2);
            }

            return (1/(Math.Sqrt(sumFunctions + Math.Pow(prodXj - 1, 2))));
        }
    }
}
